﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication5.UILayer
{
    public partial class MenuPrincipal : Form
    {
        public string nombreUsuario;

        public MenuPrincipal()
        {
            InitializeComponent();
            
        }


        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "Archivos de texto (*.txt)|*.txt|Todos los archivos (*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
                // TODO: agregar código aquí para abrir el archivo.
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "Archivos de texto (*.txt)|*.txt|Todos los archivos (*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
                // TODO: agregar código aquí para guardar el contenido actual del formulario en un archivo.
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

       

        private void administrarToolStripMenuItem_Click(object sender, EventArgs e)
        {
           

            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmGestionAfiliaciones)
                {
                    existe = true;
                    ((frmGestionAfiliaciones)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmGestionAfiliaciones f = new frmGestionAfiliaciones();
                f.MdiParent = this;
                f.Show();
            }

        }

        private void grupoFamiliarToolStripMenuItem_Click(object sender, EventArgs e)
        {

            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmGrupoFamiliar)
                {
                    existe = true;
                    ((frmGrupoFamiliar)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmGrupoFamiliar f = new frmGrupoFamiliar();
                f.MdiParent = this;
                f.Show();
            }

        }

        private void administrarToolStripMenuItem2_Click(object sender, EventArgs e)
        {

            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmColegios)
                {
                    existe = true;
                    ((frmColegios)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmColegios f = new frmColegios();
                f.MdiParent = this;
                f.Show();
            }

        }

        private void colegiosToolStripMenuItem_Click(object sender, EventArgs e)
        {

            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmABMConvenioColegio)
                {
                    existe = true;
                    ((frmABMConvenioColegio)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmABMConvenioColegio f = new frmABMConvenioColegio();
                f.MdiParent = this;
                f.Show();
            }

        }

        private void institucionesToolStripMenuItem1_Click(object sender, EventArgs e)
        {

            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmConvenioInstitucion)
                {
                    existe = true;
                    ((frmConvenioInstitucion)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmConvenioInstitucion f = new frmConvenioInstitucion();
                f.MdiParent = this;
                f.Show();
            }

        }

        private void farmaciasToolStripMenuItem1_Click(object sender, EventArgs e)
        {

            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmConvenioFarmacia)
                {
                    existe = true;
                    ((frmConvenioFarmacia)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmConvenioFarmacia f = new frmConvenioFarmacia();
                f.MdiParent = this;
                f.Show();
            }

        }

        private void institucionesToolStripMenuItem_Click(object sender, EventArgs e)
        {

            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmInstituciones)
                {
                    existe = true;
                    ((frmInstituciones)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmInstituciones f = new frmInstituciones();
                f.MdiParent = this;
                f.Show();
            }

        }

      
        private void farmaciasToolStripMenuItem_Click(object sender, EventArgs e)
        {

            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmABMFarmacias)
                {
                    existe = true;
                    ((frmABMFarmacias)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmABMFarmacias f = new frmABMFarmacias();
                f.MdiParent = this;
                f.Show();
            }

        }

        private void especialidadesToolStripMenuItem_Click(object sender, EventArgs e)
        {

            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmABMEspecialidades)
                {
                    existe = true;
                    ((frmABMEspecialidades)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmABMEspecialidades f = new frmABMEspecialidades();
                f.MdiParent = this;
                f.Show();
            }

        }

        private void practicasToolStripMenuItem_Click(object sender, EventArgs e)
        {

            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmABMPracticas)
                {
                    existe = true;
                    ((frmABMPracticas)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmABMPracticas f = new frmABMPracticas();
                f.MdiParent = this;
                f.Show();
            }

        }

        private void comprobantesToolStripMenuItem_Click(object sender, EventArgs e)
        {

            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmConsultaComprobantes)
                {
                    existe = true;
                    ((frmConsultaComprobantes)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmConsultaComprobantes f = new frmConsultaComprobantes();
                f.MdiParent = this;
                f.Show();
            }

        }

        private void prestadoresToolStripMenuItem1_Click(object sender, EventArgs e)
        {

            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmConsultaPrestadores)
                {
                    existe = true;
                    ((frmConsultaPrestadores)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmConsultaPrestadores f = new frmConsultaPrestadores();
                f.MdiParent = this;
                f.Show();
            }

        }

        private void consultaToolStripMenuItem_Click(object sender, EventArgs e)
        {

            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmOrdenesAtencion)
                {
                    existe = true;
                    ((frmOrdenesAtencion)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmOrdenesAtencion f = new frmOrdenesAtencion();
                f.MdiParent = this;
                f.Show();
            }

        }

        private void farmaciaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmOrdenesFarmacia)
                {
                    existe = true;
                    ((frmOrdenesFarmacia)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmOrdenesFarmacia f = new frmOrdenesFarmacia();
                f.MdiParent = this;
                f.Show();
        }
    }

        private void imprimirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmImprimirOrdenes)
                {
                    existe = true;
                    ((frmImprimirOrdenes)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmImprimirOrdenes f = new frmImprimirOrdenes();
                f.MdiParent = this;
                f.Show();
        }
}

        private void autorizarComplejasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmAutorizarComplejos)
                {
                    existe = true;
                    ((frmAutorizarComplejos)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmAutorizarComplejos f = new frmAutorizarComplejos(nombreUsuario);
                f.MdiParent = this;
                f.Show();
        }

        }
        private void prácticasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmInformePracticas)
                {
                    existe = true;
                    ((frmInformePracticas)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmInformePracticas f = new frmInformePracticas();
                f.MdiParent = this;
                f.Show();
        }}

        private void recaudaciónToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmInformeRecaudacion)
                {
                    existe = true;
                    ((frmInformeRecaudacion)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmInformeRecaudacion f = new frmInformeRecaudacion();
                f.MdiParent = this;
                f.Show();
        }}

        private void prestadoresToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmNuevosPrestadores)
                {
                    existe = true;
                    ((frmNuevosPrestadores)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmNuevosPrestadores f = new frmNuevosPrestadores();
                f.MdiParent = this;
                f.Show();
            }
        }

        private void normasAdministrativasToolStripMenuItem_Click(object sender, EventArgs e)
        {

            //bool existe = false;
            //int i = 0;

            //while (i < (this.MdiChildren.Length) & (!existe))
            //{
            //    if (this.MdiChildren[i] is frmBAJANormasAdministrativas)
            //    {
            //        existe = true;
            //        ((frmBAJANormasAdministrativas)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
            //    }
            //    i++;
            //}

            //if (!existe)
            //{
            //    frmBAJANormasAdministrativas f = new frmBAJANormasAdministrativas();
            //    f.MdiParent = this;
            //    f.Show();
            //}
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is Acercade)
                {
                    existe = true;
                    ((Acercade)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                Acercade f = new Acercade();
                f.MdiParent = this;
                f.Show();
        }}

        private void administrarToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmABMPracticas)
                {
                    existe = true;
                    ((frmABMPracticas)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmABMPracticas f = new frmABMPracticas();
                f.MdiParent = this;
                f.Show();
            }
        }

        private void MenuPrincipal_Load(object sender, EventArgs e)
        {
            frmLogin login = new frmLogin();                            
            menuStrip.Visible = false;

            login.ShowDialog();

            if (login.EstadoLogin())
            {
                menuStrip.Visible = true;
                this.nombreUsuario = login.usuarioNombre;
            }
            else 
            {
                this.Close();
            }      
        }

        private void nuevoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmABMProfesionales)
                {
                    existe = true;
                    ((frmABMProfesionales)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmABMProfesionales f = new frmABMProfesionales();
                f.MdiParent = this;
                f.Show();
            }

        }

        private void asignarEspecialiadesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmABMEspecialidadesProfesionales)
                {
                    existe = true;
                    ((frmABMEspecialidadesProfesionales)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmABMEspecialidadesProfesionales f = new frmABMEspecialidadesProfesionales();
                f.MdiParent = this;
                f.Show();
            }

        }

        private void itemUsuarios_Click(object sender, EventArgs e)
        {
            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmUsuarios)
                {
                    existe = true;
                    ((frmUsuarios)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmUsuarios f = new frmUsuarios();
                f.MdiParent = this;
                f.Show();
            }
        }

        private void itemGrupos_Click(object sender, EventArgs e)
        {
            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmGrupos)
                {
                    existe = true;
                    ((frmGrupos)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmGrupos f = new frmGrupos();
                f.MdiParent = this;
                f.Show();
            }
        }

        private void itemPantallasGrupo_Click(object sender, EventArgs e)
        {
            bool existe = false;
            int i = 0;

            while (i < (this.MdiChildren.Length) & (!existe))
            {
                if (this.MdiChildren[i] is frmPantallasXGrupo)
                {
                    existe = true;
                    ((frmPantallasXGrupo)this.MdiChildren[i]).WindowState = FormWindowState.Normal;
                }
                i++;
            }

            if (!existe)
            {
                frmPantallasXGrupo f = new frmPantallasXGrupo();
                f.MdiParent = this;
                f.Show();
            }
        }
    }
}